import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/register")
public class RegisterServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");

        response.setContentType("text/html;charset=UTF-8");

        // 修改逻辑：当用户名或密码为空时提示注册失败，否则提示注册成功
        if ((username == null || username.trim().isEmpty()) || (password == null || password.trim().isEmpty())) {
            response.getWriter().println("注册失败<br>");
            if (username == null || username.trim().isEmpty()) {
                response.getWriter().println("注意：用户名为空<br>");
            }
            if (password == null || password.trim().isEmpty()) {
                response.getWriter().println("注意：密码为空<br>");
            }
        } else {
            response.getWriter().println("注册成功<br>");
            response.getWriter().println("页面输入的用户名=" + username + "<br>");
            response.getWriter().println("页面输入的密码=" + password);
        }
    }
}